﻿using MediatR;
using Traceability.App.Applications.Command.Health;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.CommandHand.Health
{
    public class GetHealthCommandHand : IRequestHandler<GetHealthCommand, ApiResult<List<HealthModel>>>
    {

        private readonly IBaseRepository<HealthModel> _helath;

        public GetHealthCommandHand(IBaseRepository<HealthModel> helath)
        {
            _helath = helath;
        }

        public Task<ApiResult<List<HealthModel>>> Handle(GetHealthCommand request, CancellationToken cancellationToken)
        {

            var result=new ApiResult<List<HealthModel>>();
            var helthrlist=_helath.GetAll().Where(x=>x.Batch==request.Batch&&x.del==0).ToList();

            result.data = helthrlist;
            result.Code=ApiEnum.ok;
            return Task.FromResult(result);


        }
    }
}
